navbarController.$inject = ['$rootScope','$http', '$location', 'navMenuService'];

var appContext = require('../../../../config/app.context');

function navbarController($rootScope, $http, $location, navMenuService) {
    // alert('nav bar ctrl');

    var vm = this;

    vm.menus = navMenuService.getMenus();

    vm.dishTypes = ['所有', '酒水', '套餐', '小吃', '主食'];

    vm.search = {
        type: 0,
        keyWord: ''
    };
    vm.getDishType = function() {
        return vm.dishTypes[vm.search.type];
    }
    vm.doDishSearch = function($event) {
        $event.preventDefault();
        // console.log(vm.search);
        // $location.path($location.path() + '?type=' + vm.search.type + '&keyword=' + vm.search.keyWord);
        $rootScope.$broadcast('doDishSearch', vm.search);
    }

    vm.doLogout = function() {
        $http.delete(appContext.path + '/api/customers/logout').then(
            function(response) {
                if ($location.path().indexOf(appContext.path + '/home') == -1) {
                    $location.path(appContext.path + '/home');
                } else {
                    window.location.reload();
                }
            },
            function(err) {
                console.log(err.data);
            }
        );
    }


    // $http.get(appContext.path + '/api/dishTypes').then(
    //     function(response) {
    //         if (response.data.result) {
    //             vm.dishTypes = response.data.data;
    //         }
    //     },
    //     function(err) {
    //         console.log(err.data);
    //     }
    // );

}

module.exports = navbarController;